﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using devtm.Aop.InternalProcess.Cache;
using devtm.Aop.InternalProcess;
using devtm.Aop.Event;
using devtm.Aop.InternalProcess.Lock;

namespace devtm.Aop.Behavior
{


    /// <summary>
    /// Inherit from InterceptMethodAttribute and intercept the entry and exit method event
    /// </summary>
    public class LogAttribute : InterceptMethodAttribute
    {


        public LogAttribute() : base()
        {
        
        }


        /// <summary>
        /// called in begining from the intercepted method
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="args">The <see cref="devtm.Aop.Event.InterceptEventArgs"/> instance containing the event data.</param>
        public override void EntryMethod(object sender, InterceptEventArgs args)
        {

            string category = args.Properties.Get("Category") as string ?? string.Empty;
            System.Diagnostics.Debug.Indent();
            StringBuilder s = new StringBuilder();
            System.Diagnostics.Debug.WriteLine(args.Member.ToString()  + " " + InterceptEventArgsHelper.SerializeParameters(s, args), category);

        }


        /// <summary
        /// called in end from the intercepted method
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="args">The <see cref="devtm.Aop.Event.InterceptEventArgs"/> instance containing the event data.</param>
        public override void ExitMethod(object sender, InterceptEventArgs args)
        {
            System.Diagnostics.Debug.Unindent();
        }


        public string Category { get; set; }
    }
}
